import axios from '../index'
import type { mostNewPI } from '../../type/index'

/**
 * 请求轮播图数据
 * @returns {Promise} Promise
 */
const getSliders = (): Promise<any> => axios.get('/api/slider/getSliders')

/**
 * 请求课程列表数据
 * @param {{pageNum;pageSize;}} data
 * @param {number} params.pageNum - 页数
 * @param {number} params.pageSize - 条数
 * @param {Object | null} params.entity - 查询对象
 * @returns {Promise} Promise
 */
const mostNew = (data: mostNewPI): Promise<any> => axios.post('/api/course/mostNew', data)

/**
 * 获取一级分类数据
 * @returns {Promise}
 */
const getFirstCategories = (): Promise<any> => axios.get('/api/course/category/getFirstCategorys')

/**
 * 获取二级分类数据
 * @param {categoryId} params
 * @param {string} params.categoryId - 上级分类Id
 * @returns 
 */
const getSecondCategories =
  (params: object): Promise<any> => axios.get('/api/course/category/getSecondCategorys', { params })

/**
 * 获取课程数据
 * @param {{pageNum,pageSize}} data 
 * @param {number} data.pageSize 
 * @param {number} data.pageNum 
 * @returns {Promise} Promise
 */
const courseSearch = (data: object): Promise<any> => axios.post('/api/course/search', { data })

/**
 * 课程详情
 * @param {id} params 
 * @param {string} params.id 
 * @returns {Promise} Promise
 */
const getDetail = (params: object): Promise<any> => axios.get('/api/course/getDetail', { params })


export {
  getSliders,
  mostNew,
  getFirstCategories,
  getSecondCategories,
  courseSearch,
  getDetail,
}